﻿
Imports System.Data.SqlClient
Imports QuanLyBanChau.KhachHang

Public Class KhachHang_dao
    Public Shared Sub insertKhachHangdao(ByVal KhachHang As KhachHang)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(7) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("insert_KhachHang", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(0) = New SqlParameter(" @Makhachhang", SqlDbType.VarChar, 10)
        para(0).Value = KhachHang.Makhachhang
        cmd.Parameters.Add(para(0))
        para(1) = New SqlParameter(" @Ten", SqlDbType.NVarChar, 10)
        para(1).Value = KhachHang.Ten
        cmd.Parameters.Add(para(1))

        para(2) = New SqlParameter(" @Diachi", SqlDbType.NVarChar, 10)
        para(2).Value = KhachHang.Diachi
        cmd.Parameters.Add(para(2))

        para(3) = New SqlParameter(" @Maloaikhachhang", SqlDbType.VarChar, 10)
        para(3).Value = KhachHang.Maloaikhachhang
        cmd.Parameters.Add(para(3))

        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub


    Public Shared Sub DeleteKhachHangdao(ByVal Makhachhang)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(1) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Delete_KhachHang", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(1) = New SqlParameter(" @Makhachhang", SqlDbType.VarChar, 10)
        para(1).Value = Makhachhang
        cmd.Parameters.Add(para(1))
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub
    Public Shared Function Get_KhachHangdao()
        Dim conn As SqlConnection
        conn = dataprovider.Connection()
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        da.SelectCommand = New SqlCommand
        da.SelectCommand.Connection = conn
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        da.SelectCommand.CommandText = "Get_KhachHang"
        da.Fill(dt)
        Return dt
    End Function

    Public Shared Sub UpdateChaudao(ByVal KhachHang As KhachHang)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(7) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Update_KhachHang", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(0) = New SqlParameter(" @Makhachhang", SqlDbType.VarChar, 10)
        para(0).Value = KhachHang.Makhachhang
        cmd.Parameters.Add(para(0))
        para(1) = New SqlParameter(" @Ten", SqlDbType.NVarChar, 10)
        para(1).Value = KhachHang.Ten
        cmd.Parameters.Add(para(1))

        para(2) = New SqlParameter(" @Diachi", SqlDbType.NVarChar, 10)
        para(2).Value = KhachHang.Diachi
        cmd.Parameters.Add(para(2))

        para(3) = New SqlParameter(" @Maloaikhachhang", SqlDbType.VarChar, 10)
        para(3).Value = KhachHang.Maloaikhachhang
        cmd.Parameters.Add(para(3))

        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub



End Class
